let getData = require("./getData");

async function 返回牙叔教程(keyword, all) {
    let data = await getData();
    var len = data.length;
    // keyword = keyword.trim();
    keyword = keyword.replace(/\s/g, "");
    let arr = [];
    for (var i = 0; i < len; i++) {
        let item = data[i];
        // {
        //   "type": "DOC",
        //   "title": "无障碍检测",
        //   "uuid": "XOOJ8Yvvfes93uoO",
        //   "url": "qakz8g",
        //   "prev_uuid": "",
        //   "sibling_uuid": "8y6bTj0kocRg5IEX",
        //   "child_uuid": "",
        //   "parent_uuid": "",
        //   "doc_id": 54543438,
        //   "level": 0,
        //   "id": 54543438,
        //   "open_window": 1,
        //   "visible": 1
        // },
        if (item.title.toLowerCase().indexOf(keyword.toLowerCase()) > -1) {
            let url = "https://www.yuque.com/yashujs/bfug6u";
            arr.push(item.title + "\n" + url + "/" + item.url);
        }
    }
    if (arr.length > 3) {
        if (!all) {
            arr.length = 3;
        }
    }
    if (arr.length > 0) {
        let result = arr.join("\n");
        console.log(result);
        return result;
    } else {
        return false;
    }
}

module.exports = 返回牙叔教程;
